package cn.ytnet.shangyun.service.basic.entity;

import org.springframework.stereotype.Component;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.List;
import java.util.Set;

/**
 * Created by cyongk on 2015/12/8.
 * ClassName：GoodsEntity
 * ChineseName：商品类
 */
@Component("goodsEntity")
@Entity
@Table(name = "T_Goods", schema = "crebas", catalog = "")
public class GoodsEntity {
    private String pkTGoodsStorecode;
    private String goodsName;
    private String goodsSize;
    private String goodsModel;
    private String goodsLten;
    private String mainTime;
    private int storageProperty;
    private BigDecimal purchasePrice;
    private BigDecimal retailPrice;
    private BigDecimal wholesalePrice;
    private BigDecimal memberPrice;


    /*系统用户*/
    private UserEntity userEntity;//用户

    /*商品相关类*/
    private GoodsUnitEntity goodsUnitEntity;//商品单位
    private GoodsStockEntity goodsStockEntity;//商品库存
    private List<GoodsCodeEntity> goodsCodeEntity;//商品条码
    private GoodsTotalSortEntity goodsTotalSortEntity;//商品总分类
    private GoodsSubSortEntity goodsSubSortEntity;//商品子分类
    private Set<WarehouseInfoEntity> warehouseInfoEntity;//商品仓库
    private Set<SupplierEntity> supplierEntity;//供应商

    /*行政区域*/
    private ProvinceEntity provinceEntity;//省（直辖市）
    private CityEntity cityEntity;//市（地区、城市）
    private CountyEntity countyEntity;//县（区）
    private TownEntity townEntity;//镇（乡）

    @ManyToOne(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
    @JoinColumn(name = "pk_t_user_id")
    public UserEntity getUserEntity() {
        return userEntity;
    }

    public void setUserEntity(UserEntity userEntity) {
        this.userEntity = userEntity;
    }

    @ManyToOne(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
    @JoinColumn(name = "pk_t_goodsunit_id")
    public GoodsUnitEntity getGoodsUnitEntity() {
        return goodsUnitEntity;
    }

    public void setGoodsUnitEntity(GoodsUnitEntity goodsUnitEntity) {
        this.goodsUnitEntity = goodsUnitEntity;
    }

    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "pk_T_goodsstock_id")
    public GoodsStockEntity getGoodsStockEntity() {
        return goodsStockEntity;
    }

    public void setGoodsStockEntity(GoodsStockEntity goodsStockEntity) {
        this.goodsStockEntity = goodsStockEntity;
    }

    @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
    @JoinColumn(name = "pk_t_goodscode_id")
    public List<GoodsCodeEntity> getGoodsCodeEntity() {
        return goodsCodeEntity;
    }

    public void setGoodsCodeEntity(List<GoodsCodeEntity> goodsCodeEntity) {
        this.goodsCodeEntity = goodsCodeEntity;
    }

    @ManyToOne(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
    @JoinColumn(name = "pk_t_goodsgotalsort_id")
    public GoodsTotalSortEntity getGoodsTotalSortEntity() {
        return goodsTotalSortEntity;
    }

    public void setGoodsTotalSortEntity(GoodsTotalSortEntity goodsTotalSortEntity) {
        this.goodsTotalSortEntity = goodsTotalSortEntity;
    }

    @ManyToOne(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
    @JoinColumn(name = "pkT_goodssubsort_id")
    public GoodsSubSortEntity getGoodsSubSortEntity() {
        return goodsSubSortEntity;
    }

    public void setGoodsSubSortEntity(GoodsSubSortEntity goodsSubSortEntity) {
        this.goodsSubSortEntity = goodsSubSortEntity;
    }

    @ManyToMany(cascade=CascadeType.ALL)
    @JoinTable(
            name="t_goods_has_t_supplier",
            joinColumns={@JoinColumn(name="pk_t_goods_storecode")},
            inverseJoinColumns={@JoinColumn(name="pk_t_supplier_id")}
    )
    public Set<WarehouseInfoEntity> getWarehouseInfoEntity() {
        return warehouseInfoEntity;
    }

    public void setWarehouseInfoEntity(Set<WarehouseInfoEntity> warehouseInfoEntity) {
        this.warehouseInfoEntity = warehouseInfoEntity;
    }

    @ManyToMany(cascade=CascadeType.ALL)
    @JoinTable(
            name="t_goods_has_t_warehouseinfo",
            joinColumns={@JoinColumn(name="pk_t_goods_storecode")},
            inverseJoinColumns={@JoinColumn(name="pk_t_warehouseinfo_id")}
    )
    public Set<SupplierEntity> getSupplierEntity() {
        return supplierEntity;
    }

    public void setSupplierEntity(Set<SupplierEntity> supplierEntity) {
        this.supplierEntity = supplierEntity;
    }

    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "pk_t_province_id")
    public ProvinceEntity getProvinceEntity() {
        return provinceEntity;
    }

    public void setProvinceEntity(ProvinceEntity provinceEntity) {
        this.provinceEntity = provinceEntity;
    }

    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "pk_t_city_id")
    public CityEntity getCityEntity() {
        return cityEntity;
    }

    public void setCityEntity(CityEntity cityEntity) {
        this.cityEntity = cityEntity;
    }

    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "pk_t_county_id")
    public CountyEntity getCountyEntity() {
        return countyEntity;
    }

    public void setCountyEntity(CountyEntity countyEntity) {
        this.countyEntity = countyEntity;
    }

    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "pk_t_town_id")
    public TownEntity getTownEntity() {
        return townEntity;
    }

    public void setTownEntity(TownEntity townEntity) {
        this.townEntity = townEntity;
    }

    @Id
    @Column(name = "pk_t_goods_storecode", nullable = false, length = 13)
    public String getPkTGoodsStorecode() {
        return pkTGoodsStorecode;
    }

    public void setPkTGoodsStorecode(String pkTGoodsStorecode) {
        this.pkTGoodsStorecode = pkTGoodsStorecode;
    }

    @Basic
    @Column(name = "goods_name", nullable = false, length = 200)
    public String getGoodsName() {
        return goodsName;
    }

    public void setGoodsName(String goodsName) {
        this.goodsName = goodsName;
    }

    @Basic
    @Column(name = "goods_size", nullable = false, length = 100)
    public String getGoodsSize() {
        return goodsSize;
    }

    public void setGoodsSize(String goodsSize) {
        this.goodsSize = goodsSize;
    }

    @Basic
    @Column(name = "goods_model", nullable = false, length = 100)
    public String getGoodsModel() {
        return goodsModel;
    }

    public void setGoodsModel(String goodsModel) {
        this.goodsModel = goodsModel;
    }

    @Basic
    @Column(name = "goods_lten", nullable = false, length = 100)
    public String getGoodsLten() {
        return goodsLten;
    }

    public void setGoodsLten(String goodsLten) {
        this.goodsLten = goodsLten;
    }

    @Basic
    @Column(name = "main_time", nullable = false, length = 100)
    public String getMainTime() {
        return mainTime;
    }

    public void setMainTime(String mainTime) {
        this.mainTime = mainTime;
    }

    @Basic
    @Column(name = "storage_property", nullable = false)
    public int getStorageProperty() {
        return storageProperty;
    }

    public void setStorageProperty(int storageProperty) {
        this.storageProperty = storageProperty;
    }

    @Basic
    @Column(name = "purchase_price", nullable = false, precision = 2)
    public BigDecimal getPurchasePrice() {
        return purchasePrice;
    }

    public void setPurchasePrice(BigDecimal purchasePrice) {
        this.purchasePrice = purchasePrice;
    }

    @Basic
    @Column(name = "retail_price", nullable = false, precision = 2)
    public BigDecimal getRetailPrice() {
        return retailPrice;
    }

    public void setRetailPrice(BigDecimal retailPrice) {
        this.retailPrice = retailPrice;
    }

    @Basic
    @Column(name = "wholesale_price", nullable = false, precision = 2)
    public BigDecimal getWholesalePrice() {
        return wholesalePrice;
    }

    public void setWholesalePrice(BigDecimal wholesalePrice) {
        this.wholesalePrice = wholesalePrice;
    }

    @Basic
    @Column(name = "member_price", nullable = false, precision = 2)
    public BigDecimal getMemberPrice() {
        return memberPrice;
    }

    public void setMemberPrice(BigDecimal memberPrice) {
        this.memberPrice = memberPrice;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        GoodsEntity that = (GoodsEntity) o;

        if (storageProperty != that.storageProperty) return false;
        if (pkTGoodsStorecode != null ? !pkTGoodsStorecode.equals(that.pkTGoodsStorecode) : that.pkTGoodsStorecode != null)
            return false;
        if (goodsName != null ? !goodsName.equals(that.goodsName) : that.goodsName != null) return false;
        if (goodsSize != null ? !goodsSize.equals(that.goodsSize) : that.goodsSize != null) return false;
        if (goodsModel != null ? !goodsModel.equals(that.goodsModel) : that.goodsModel != null) return false;
        if (goodsLten != null ? !goodsLten.equals(that.goodsLten) : that.goodsLten != null) return false;
        if (mainTime != null ? !mainTime.equals(that.mainTime) : that.mainTime != null) return false;
        if (purchasePrice != null ? !purchasePrice.equals(that.purchasePrice) : that.purchasePrice != null)
            return false;
        if (retailPrice != null ? !retailPrice.equals(that.retailPrice) : that.retailPrice != null) return false;
        if (wholesalePrice != null ? !wholesalePrice.equals(that.wholesalePrice) : that.wholesalePrice != null)
            return false;
        return memberPrice != null ? memberPrice.equals(that.memberPrice) : that.memberPrice == null;

    }

    @Override
    public int hashCode() {
        int result = pkTGoodsStorecode != null ? pkTGoodsStorecode.hashCode() : 0;
        result = 31 * result + (goodsName != null ? goodsName.hashCode() : 0);
        result = 31 * result + (goodsSize != null ? goodsSize.hashCode() : 0);
        result = 31 * result + (goodsModel != null ? goodsModel.hashCode() : 0);
        result = 31 * result + (goodsLten != null ? goodsLten.hashCode() : 0);
        result = 31 * result + (mainTime != null ? mainTime.hashCode() : 0);
        result = 31 * result + storageProperty;
        result = 31 * result + (purchasePrice != null ? purchasePrice.hashCode() : 0);
        result = 31 * result + (retailPrice != null ? retailPrice.hashCode() : 0);
        result = 31 * result + (wholesalePrice != null ? wholesalePrice.hashCode() : 0);
        result = 31 * result + (memberPrice != null ? memberPrice.hashCode() : 0);
        return result;
    }
}
